const Mock = require('mockjs')

const List = []
const count = 100

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
  id: '@increment',
  'plc|1': ['PLC_1','PLC_2'],
  'address|1': ['DB100,Real0','DB100,Real4','DB100,Real8','DB100,Real12','DB100,Real16'],
  type: 'Real',
  value: '@increment',
  'status|1': ['激活','未激活'],
  rw: 'W',
  factory: '@increment',
  property: 'null',
  description: '@title(5, 20)',
  date: '@datetime',
  }))
}


module.exports = [
  {
    url: '/trend/getTrendList',
    type: 'get',
    response: config => {
      const {  address, status, page = 1, limit = 20, sort } = config.query
      let mockList = List.filter(item => {

        if (status && item.status !== status) return false
        if (address && item.address.indexOf(address) < 0) return false

        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },
]

